@isTest
private class testOptySolutionControllerExtension
{
 static testMethod void testOpportunitySolutionController()
  {

   // Inserted an opportunity for aa solution to be associated to it later   
    Opportunity  opty1 = new Opportunity();
    opty1.Name='TestOpty1';
    opty1.CloseDate=system.today();
    opty1.StageName='Prospecting';
    insert opty1;
    
   // fetch the record types available for solution Object 
    List<Schema.RecordTypeInfo> recinfo = Solution__C.SObjectType.getDescribe().getRecordTypeInfos();
    List<ID> recType = new List<ID>();
    For(integer i=0;i<recinfo.size() ;i++)
    {
     recType.add(recinfo[i].getRecordTypeID());
     system.debug('+++++ record type name ' + recinfo[i].getName());
    }
   
         
       Solution__c solcon = new Solution__c();
       solcon.Opportunity__c = opty1.id;  
       solcon.opportunity__r = opty1;
       solcon.Product__c = 'Upgrade';  // to test the validation rule 'Requiredfield'
       solcon.recordtypeID = recType[0];//inserted the 'consulting' recordtype
       
       Solution__c solout = new Solution__c();
       solout.Opportunity__c = opty1.id;  
       solout.opportunity__r = opty1;
       solout.Product__c = 'HR Outsourcing';  // to test the validation rule 'Requiredfield'
       solout.recordtypeID = recType[1];//inserted the 'Outsourcing' recordtype
       
       Solution__c solsoft = new Solution__c();
       solsoft.Opportunity__c = opty1.id;  
       solsoft.opportunity__r = opty1;
       solsoft.Product__c = 'Optimum';  // to test the validation rule 'Requiredfield'
       solsoft.recordtypeID = recType[2];//inserted the 'Software' recordtype
       
        
       insert solcon; 
       insert solout;
       insert solsoft;
        
      
  //Passed the solution created to myControllerExtension  constructor
    
   OpportunitySolutionExtensionController myExt1 = new OpportunitySolutionExtensionController(new ApexPages.standardController(solcon));
    OpportunitySolutionExtensionController myExt2 = new OpportunitySolutionExtensionController(new ApexPages.standardController(solout));
    OpportunitySolutionExtensionController myExt3 = new OpportunitySolutionExtensionController(new ApexPages.standardController(solsoft));
    //system.debug('solution +++ ' + myExt.soln);  
   
   
   
   myExt1.initialise();
   myExt1.NewSolutionComponent();   
   PageReference pageref1;
   pageref1= myExt1.Save();
   //system.debug(' id ++++++++++ ' + myExt1.Components.get(0));
   system.assertequals(myExt1.Components.get(0).solution__c,solcon.id);
   
   myExt2.initialise();
   myExt2.NewSolutionComponent();   
   PageReference pageref2;
   pageref2= myExt2.Save();
   system.assertequals(myExt2.Components.get(0).solution__c,solout.id);
   
   myExt3.initialise();
   myExt3.NewSolutionComponent();   
   PageReference pageref3;
   pageref3= myExt3.Save();
   system.assertequals(myExt1.Components.get(0).solution__c,solsoft.id);
   
   
   
  
  } 
  
}